package com.stockz.equity.charting.view.widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.JButton;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.event.EventPublisher;
import com.stockz.equity.charting.event.RepaintStockChartPanelEvent;
import com.stockz.equity.charting.view.StockChartPanelState;
import com.stockz.equity.charting.view.StockChartView;
import com.stockz.equity.charting.view.toolbar.ViewToolbar;
import com.stockz.equity.pattern.Child;

@Component
public class SemiLogButton extends JButton implements Child,ActionListener {
	private static final long serialVersionUID = 3816910076124277741L;

	@SuppressWarnings("unchecked")
	private List<Class> parentList = new ArrayList<Class>();
	@Autowired StockChartView stockChartView;
	
	public SemiLogButton(){
		super("Semilog");
		parentList.add(ViewToolbar.class);
		addActionListener(this);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Collection<Class> getParents() {
		return parentList;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		StockChartPanelState state = stockChartView.getSelectedStockChart()
		.getStockChartPanel().getStockChartPanelState();
		if(state.isSemiLog()){
			state.setSemiLog(false);
			setText("Semilog");
		}else{
			state.setSemiLog(true);
			setText("Linier");
		}
		EventPublisher.publishEvent(
				new RepaintStockChartPanelEvent(
						stockChartView.getSelectedStockChart().getStockChartPanel()));
	}
}
